{CACHE} = require('../redis')
b64id = require '../../util/b64id'

DURATION_DAY = 86400

class Key
    constructor: (@prefix) ->
    new : (val)->
        key = b64id()
        await CACHE.setex(
            @prefix+key
            DURATION_DAY
            val
        )
        return key
    get:(key)->
        await CACHE.get(@prefix+key)
    del:(key)->
        await CACHE.del(@prefix+key)
    renew:(key)->
        await CACHE.expire(@prefix+key, DURATION_DAY)

module.exports = (prefix)->
    new Key(prefix)
